<?php
// +----------------------------------------------------------------------
// | 小牛Admin
// +----------------------------------------------------------------------
// | Website: www.xnadmin.cn
// +----------------------------------------------------------------------
// | Author: dav <85168163@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\validate;

use think\Validate;

class Login extends Validate
{
    protected $rule = [
        'username' => 'require',
        'password' => 'require',
        'vercode' => 'require|checkCaptcha'
    ];

    protected $message = [
        'username.require' => '账号不能为空！',
        'password.require' => '密码不能为空！',
        'vercode.require' => '验证码不能为空！',
    ];

    protected $scene = [
        'login' => ['username','password','vercode']
    ];

    /**
     * 自定义验证验证码方法
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool|string
     */
    protected function checkCaptcha($value,$rule,$data = []){
        // 验证验证码
        if (!captcha_check($value)){
            // 验证码校验失败
            return '验证码不正确';
        }
        return true;
    }
}
